当前位置: 技术问答>java相关
请问谁有用JDBC连接MySQL的样例程序?
来源: 互联网 发布时间:2017-04-18
本文导语: 我需要使用JDBC连接MySQL的例子程序,使用传统的方法和使用数据源的方法都可以 谢谢!! | package Mysqltest; import java.sql.*; public class DBconn {String DBDriver="org.gjt.mm.mysql.Driver"; String ConnStr="jdbc:...
我需要使用JDBC连接MySQL的例子程序,使用传统的方法和使用数据源的方法都可以
谢谢!!
谢谢!!
|
package Mysqltest;
import java.sql.*;
public class DBconn
{String DBDriver="org.gjt.mm.mysql.Driver";
String ConnStr="jdbc:mysql://localhost/my_test";
String MyUser="yzysy";
String MyPassword="yzysy";
Connection conn = null;
ResultSet rs = null;
public DBconn()
{try
{Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException e)
{System.err.println("DBconn (): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{rs = null;
try
{conn = DriverManager.getConnection(ConnStr,MyUser,MyPassword);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
}
import java.sql.*;
public class DBconn
{String DBDriver="org.gjt.mm.mysql.Driver";
String ConnStr="jdbc:mysql://localhost/my_test";
String MyUser="yzysy";
String MyPassword="yzysy";
Connection conn = null;
ResultSet rs = null;
public DBconn()
{try
{Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException e)
{System.err.println("DBconn (): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{rs = null;
try
{conn = DriverManager.getConnection(ConnStr,MyUser,MyPassword);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
}
|
String DBDriver="org.gjt.mm.mysql.Driver"
请问mm.mysql.Driver如何设置?
请问mm.mysql.Driver如何设置?
|
driver:org.gjt.mm.mysql.Driver
URL :jdbc:mysql://127.0.0.1:3306/MySql
URL :jdbc:mysql://127.0.0.1:3306/MySql