Application procedures in connection mysql
Abstract: In the process of connecting applications mysql
</ Td> </ tr> <tr> <td width="501" height="35" valign="top" class="ArticleTeitle"> the first mysql jdbc driver mysql-connector-java-3.0. 14-copy production-bin.jar
To the c: \ java, then run run.bat.
Run.bat says:
Set CLASSPATH = c: \ java \ mysql-connector-java-3.0.14-production-bin.jar; CLASSPATH%%
Then compile and run the following documents test.
Import java.sql .*;
Import javax.swing .*;
Import java.awt .*;
Import java.awt.event .*;
Public class TestmysqlZH extends JFrame (
Public TestmysqlZH () (
Container contentPane = getContentPane ();
ContentPane.setLayout (new GridLayout (10,1,2,2));
JLabel lb;
AddWindowListener (new WindowAdapter () (
Public void windowClosing (WindowEvent e) (
System.exit (0);
)
));
Connection Conn;
Statement Stmt;
ResultSet Rst;
String con_string = "jdbc: mysql: / / localhost: 3306";
Con_string con_string + = "/ soft? User = javauser; javadude password =";
Try (
Class.forName ( "com.mysql.jdbc.Driver");
Conn = DriverManager.getConnection (con_string);
Stmt = Conn.createStatement ();
String sql = "select soft_name from soft where soft_id <10";
Rst = Stmt.executeQuery (sql);
While (Rst.next ()) (
String s = Rst.getString (1);
S = new String (s.getBytes ( "ISO8859_1"));
System.out.println (s);
Lb = new JLabel (s);
ContentPane.add (lb);
)
) Catch (SQLException e) (
System.out.println (e);
) Catch (Exception e) (System.out.println (e);)
)
Public static void main (String args []) (
TestmysqlZH t = new TestmysqlZH ();
T.setSize (300, 300);
T.show ();
)
) </ Td> <td width="183" valign="top" class="ArticleTeitle">
</ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle">
↑ Back
Tags: Connection, java mysql, Java procedures






