这个是连接的代码//importjava.beans.Statement;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassDBLink{St...
这个是连接的代码//import java.beans.Statement;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class DBLink {String driver = "com.mysql.jdbc.Driver";String url = "jdbc:mysql://localhost:3306/mydb?characterEncoding=utf8&useSSL=true";String user = "root";String password = "wf26262854";ResultSet strRs;public DBLink(){System.out.println("数据连接开始");try{Class.forName(driver);System.out.println("驱动连接");Connection conn = DriverManager.getConnection(url, user, password);System.out.println("MySQL连接");if(!conn.isClosed())System.out.println("Succeeded connecting to the Database!");Statement statement = conn.createStatement();String sql = "select UserName from tabUser";ResultSet rs = statement.executeQuery(sql);strRs = rs;System.out.print("helloword2");}catch(Exception w){System.out.print(w);}finally{System.out.println("标志");}}}
展开