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("jdbcracle:thinMyCM: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();
}
}
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("jdbcracle:thinMyCM: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();
}
}