jsp项目中连接sqlsever的语句换成连接mysql的该怎么改啊?
packagedb;importjava.sql.*;publicclassdb{privateStringdbDriver="com.microsoft.sqlserv...
package db;
import java.sql.*;
public class db {
private String dbDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private String sConnStr = "jdbc:sqlserver://localhost:1433;databasename=jspjiazhengxns5210";
public Connection connect = null;
public ResultSet rs=null;
public db() {
try {
Class.forName(dbDriver).newInstance();
connect = DriverManager.getConnection(sConnStr,"sa","123456");
}
catch (Exception ex) {
System.out.println("12121");
}
}
public ResultSet executeQuery(String sql) {
try{
connect=DriverManager.getConnection(sConnStr,"sa","123456");
Statement stmt=connect.createStatement();
rs=stmt.executeQuery(sql);
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
Statement stmt=null;
rs=null;
try
{ connect=DriverManager.getConnection(sConnStr,"sa","123456");
stmt=connect.createStatement();
stmt.executeUpdate(sql);
stmt.close();
connect.close();
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
}
} 展开
import java.sql.*;
public class db {
private String dbDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private String sConnStr = "jdbc:sqlserver://localhost:1433;databasename=jspjiazhengxns5210";
public Connection connect = null;
public ResultSet rs=null;
public db() {
try {
Class.forName(dbDriver).newInstance();
connect = DriverManager.getConnection(sConnStr,"sa","123456");
}
catch (Exception ex) {
System.out.println("12121");
}
}
public ResultSet executeQuery(String sql) {
try{
connect=DriverManager.getConnection(sConnStr,"sa","123456");
Statement stmt=connect.createStatement();
rs=stmt.executeQuery(sql);
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
Statement stmt=null;
rs=null;
try
{ connect=DriverManager.getConnection(sConnStr,"sa","123456");
stmt=connect.createStatement();
stmt.executeUpdate(sql);
stmt.close();
connect.close();
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
}
} 展开
2014-04-20
展开全部
修改如下:1、url改为jdbc:mysql://localhost:3306/数据库名2、driverclass改为com.mysql.jdbc.Driver3、用户名和密码改成你mysql数据库的用户名和密码4、引入驱动包
展开全部
private String dbDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
中换成com.mysql.jdbc.Driver
private String sConnStr = "jdbc:sqlserver://localhost:1433;databasename=jspjiazhengxns5210"
中换成jdbc:mysql://localhost:3306/jspjiazhengxn5210。看你这数据库的名字就这么霸气!
中换成com.mysql.jdbc.Driver
private String sConnStr = "jdbc:sqlserver://localhost:1433;databasename=jspjiazhengxns5210"
中换成jdbc:mysql://localhost:3306/jspjiazhengxn5210。看你这数据库的名字就这么霸气!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-04-20
展开全部
这个编程难度太大了!还是找软件专业的毕业生吧!烦请采纳!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |