【★】jbuilder 使用JDBC访问ORACLE问题,出现"Frame1.java": Error #: 360 : unreported exceptio

  • 主题发起人 主题发起人 small_talk
  • 开始时间 开始时间
S

small_talk

Unregistered / Unconfirmed
GUEST, unregistred user!
【★】jbuilder 使用JDBC访问ORACLE问题,出现"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;【★】(100分)<br />用JDBC访问ORACLE,编译时出现下面错误,但我已经是在JBuilder加入包:
classes12.jar和nls_charset12.jar了,请问是什么问题???
"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;
must be caught or declared to be thrown at line 55, column 19
"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;
must be caught or declared to be thrown at line 56, column 61
"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;
must be caught or declared to be thrown at line 57, column 10
"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;
must be caught or declared to be thrown at line 58, column 50
"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;
must be caught or declared to be thrown at line 59, column 25
"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;
must be caught or declared to be thrown at line 60, column 11
"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;
must be caught or declared to be thrown at line 62, column 20
"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;
must be caught or declared to be thrown at line 64, column 4
"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;
must be caught or declared to be thrown at line 65, column 6
"Frame1.java": Error #: 360 : unreported exception: java.sql.SQLException;
must be caught or declared to be thrown at line 66, column 6
我的程序代码如下:
package dbtest;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import oracle.jdbc.driver.*;
public class Frame1 extends JFrame {
JPanel contentPane;
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JLabel jLabel1 = new JLabel();
/**Construct the frame*/
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jTextField1.setBounds(new Rectangle(39, 80, 160, 27));
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jButton1.setText("查询");
jButton1.setBounds(new Rectangle(215, 80, 79, 29));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jLabel1.setText("jLabel1");
jLabel1.setBounds(new Rectangle(43, 134, 203, 30));
contentPane.add(jTextField1, null);
contentPane.add(jButton1, null);
contentPane.add(jLabel1, null);
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e) {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
OracleConnection conn = (OracleConnection)DriverManager.getConnection("jdbc:oracle:thin:@MyCM:1521:SERVNAME ", "USR", "PSWD");
conn.setDefaultRowPrefetch(5);
OracleStatement stmt = (OracleStatement)conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT ID,NAME from TABLE1");
while (rs.next())
{
jLabel1.setText(rs.getString(1));
}
rs.close();
stmt.close();
conn.close();
}
}
 
我也遇到过这样的问题,驱动程序有问题,你换Oracle9i的jdbc驱动 ojdbc14.jar 即可!
 
我的oracle就是9i的
 
请问怎样才能安装好oracle的jdbc驱动呢?详细一点。。。thanks
 
我在database pilot测试过连接是成功的,但在以上代码中测试就出这样的错。??有高手在吗?????
 
void jButton1_actionPerformed(ActionEvent e) {
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
OracleConnection conn = (OracleConnection)DriverManager.getConnection("jdbc:oracle:thin:@MyCM:1521:SERVNAME ", "USR", "PSWD");
conn.setDefaultRowPrefetch(5);
OracleStatement stmt = (OracleStatement)conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT ID,NAME from TABLE1");
while (rs.next())
{
jLabel1.setText(rs.getString(1));
}
rs.close();
stmt.close();
conn.close();
}}
catch(Exception ex)
{
//必须捕获异常
}
}
 

Similar threads

I
回复
0
查看
1K
import
I
I
回复
0
查看
2K
import
I
I
回复
0
查看
3K
import
I
后退
顶部