packagedbconn;importjava.util.*;importjava.sql.*;publicclassconnmysql{publicConnectionconn;publicStatementstmt;publicResultSetrs;publicStringsqlstr="";privatefinalStringd...
package dbconn;
import java.util.*;
import java.sql.*;
public class connmysql {
public Connection conn;
public Statement stmt;
public ResultSet rs;
public String sqlstr="";
private final String db_username="root";
private final String db_userpass="123456";
private final String url="jdbc:mysql://localhost:3306/wyvip";
public connmysql(){
}
public boolean connect(){
try{
//注册数据库
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, db_username, db_userpass);
stmt = conn.createStatement();
}
catch(Exception ee){
System.out.println("connect db error:"+ee.getMessage());
return false;
}
return true;
}
public static void main(String args[]){
connmysql connsql = new connmysql();
if(connsql.connect()){
System.out.println("成功");
}
else
System.out.println("失败");
}
}
package dbconn;
import java.util.*;
import java.sql.*;
public class connmysql {
private final String db_username="root";
private final String db_userpass="123456";
private final String url="jdbc:mysql://localhost:3306/wyvip";
public Statement stmt ;
public Connection conn;
public connmysql(){
}
public boolean connect(){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url,"root","123456");
stmt=conn.createStatement();
}
catch(Exception ee){
System.out.println("connect db error"+ee.getMessage());
return false;
}
return true;
}
public static void main(String args[]){
try{
connmysql db = new connmysql();
db.connect();
}catch(Exception e){
e.printStackTrace();
}
}
}
错误 :connect db errorcom.mysql.jdbc.Driver
展开