怎么把连接mysql的代码改成连接sql的代码 5
我找了一个jsp连接mysql的程序,但是想用sql来做,怎么改.里面有单独的连接模块,下面是代码,请高手指点,谢谢.packageweb;importjava.sql....
我找了一个jsp连接mysql的程序,但是想用sql来做,怎么改.里面有单独的连接模块,下面是代码,请高手指点,谢谢.
package web;
import java.sql.*;
public class DBConnect
{
String DBDriver = "org.gjt.mm.mysql.Driver";
String DBUrl = "jdbc:mysql://localhost/bookstore?useUnicode=true&characterEncoding=gbk";
public Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
public DBConnect()
{
try{
Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException ex)
{
System.err.println(ex.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
try{
conn = DriverManager.getConnection(DBUrl, "root", "");
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.out.println(ex);
System.err.println(ex.getMessage());
}
return rs;
}
//修改、插入、删除
public void updateDb(String sql)
{
try
{
conn = DriverManager.getConnection(DBUrl, "root", "");
stmt = conn.createStatement();
stmt.executeUpdate(sql);
}catch(SQLException ex)
{
System.out.println(ex);
System.err.println(ex.getMessage());
}
}
public void close()
{
try{
conn.close();
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
}
public static void main(String args[])
{
DBConnect con = new DBConnect();
con.updateDb("insert into custom values('eeeee','11111')");
}
}
比较急,希望高手不吝赐教. 展开
package web;
import java.sql.*;
public class DBConnect
{
String DBDriver = "org.gjt.mm.mysql.Driver";
String DBUrl = "jdbc:mysql://localhost/bookstore?useUnicode=true&characterEncoding=gbk";
public Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
public DBConnect()
{
try{
Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException ex)
{
System.err.println(ex.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
try{
conn = DriverManager.getConnection(DBUrl, "root", "");
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.out.println(ex);
System.err.println(ex.getMessage());
}
return rs;
}
//修改、插入、删除
public void updateDb(String sql)
{
try
{
conn = DriverManager.getConnection(DBUrl, "root", "");
stmt = conn.createStatement();
stmt.executeUpdate(sql);
}catch(SQLException ex)
{
System.out.println(ex);
System.err.println(ex.getMessage());
}
}
public void close()
{
try{
conn.close();
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
}
public static void main(String args[])
{
DBConnect con = new DBConnect();
con.updateDb("insert into custom values('eeeee','11111')");
}
}
比较急,希望高手不吝赐教. 展开
1个回答
展开全部
代码改的很少
String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String DBUrl = "jdbc:odbc:bkstore";
可能主要是配置了
这里有个全的
http://zhidao.baidu.com/question/26822011.html
String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String DBUrl = "jdbc:odbc:bkstore";
可能主要是配置了
这里有个全的
http://zhidao.baidu.com/question/26822011.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询