Java connection database ==> There is a problem.

xiaoxiao2021-03-06  86

Import java.awt. *;

Import javax.swing. *;

Import awt.event. *;

Import java.io. *;

Import java.sql. *;

Public Class Conn Extends Jframe Implements ActionListener

{

Public static void main (String [] args) {

CONN FRAME = New conn ();

}

JButton bu1;

Jtextarea TA1;

Public conn () {

Super ("conn");

Container C = getContentPane ();

C.setLayout (null);

BU1 = New JButton ("Read ODBC Database");

Bu1.setsize (150, 20);

Bu1.setLocation (160, 20);

Bu1.addActionListener (this);

C.Add (bu1);

TA1 = New jtextarea ();

TA1.SETSIZE (420, 280); // Adjust the window size

TA1.SETLOCATION (20, 50); // Display Window

C.Add (TA1);

SetDefaultCloseOperation (jframe.exit_on_close);

Setsize (500, 400);

SetVisible (TRUE);

}

// Event processing method

Public Void ActionPerformed (ActionEvent E) {

String str1 = "";

Try {

// Load JDBC driver

Class.Forname ("Sun.jdbc.odbc.jdbcodbcdriver");

}

Catch (ClassNotFoundException E1)

{

System.out.println ("Driver NOT Found!");

}

Try {

// Use the getConnection () method to establish an object to connect ODBC

Connection con1 = drivermanager.getConNetion ("JDBC: ODBC: Protect Database"); // The previous database: grade database

// Create a Statement object to execute the SQL command

STATEMENT ST1 = con1.createstatement ();

/ / Execute the SQL command to get the scoretable data table data

ResultSet RS1 = ST1.EXECUTEQUERY ("Select * from scoretable");

// Generation is the content display of data sheet

While (RS1.NEXT ())

{

STR1 = str1 rs1.getstring (1) rs1.getstring (2) "/ t" rs1.getlong (4) "/ t" r1.getlong (5) "/ t" gtlong (6) "/ t" RS1.GETLONG (7) "/ n";

}

// Turn off the Statement object

ST1.CLOSE ();

// Turn off the ODBC connection object

Con1.close ();

TA1.SETTEXT (STR1);

JOPTIONPANE.SHOWMESSAGEDIALOG (NULL, "Data Load Success");

}

Catch (SQLEXCEPTION E2)

{

System.out.Println ("Table Not Found!");

}

}

The mistake is as follows:

Conn.java [3: 1] Package AWT.EVENT DOES NOT EXIST

Import awt.event. *;

^

CONN.JAVA [6: 1] Cannot Resolve Symbol

Symbol: Class ActionListener

Location: Class Conn

Public Class Conn Extends Jframe Implements ActionListener

^

Conn.java [8: 1] Cannot Resolve Symbol

Symbol: Class String

Location: Class Conn

Public static void main (String [] args) {

^

CONN.JAVA [31: 1] Cannot Resolve Symbol

Symbol: Class ActionEvent

Location: Class Conn

Public Void ActionPerformed (ActionEvent E) {

^

Conn.java [20: 1] addActionListener (java.awt.event.ActionListener) in javax.swing.abstract to (conn)

Bu1.addActionListener (this);

^

Conn.com [32: 1] Cannot Resolve Symbol

Symbol: Class String

Location: Class Conn

String str1 = "";

^

CONN.JAVA [43: 1] Cannot Resolve Symbol

Symbol: Method getConne (java.lang.string)

Location: Class Java.sql.driverManager

Connection con1 = drivermanager.getConNetion ("JDBC: ODBC: Protect Database"); // The previous database: grade database

^

7 Errors

Compile CONN.

Currently, try to debug, if you understand, please give me some guidance?

转载请注明原文地址:https://www.9cbs.com/read-105905.html

New Post(0)