怎么把access数据库程序代码改成sql2005
packagedbBean;importjava.sql.*;publicclassDBBean{privateStringdriverStr="sun.jdbc.odb...
package dbBean;
import java.sql.*;
public class DBBean
{
private String driverStr = "sun.jdbc.odbc.JdbcOdbcDriver";
private String connStr = "jdbc:odbc:mydbsource";
private Connection conn = null;
private Statement stmt = null;
public DBBean()
{
try {
Class.forName(driverStr);
}
catch(ClassNotFoundException ex) {
System.out.println(ex.getMessage());
}
}
public void setDriverStr(String dstr)
{
driverStr=dstr;
}
public void setConnStr(String cstr)
{
connStr=cstr;
}
public ResultSet executeQuery(String sql)
{
ResultSet rs = null;
try {
conn = DriverManager.getConnection(connStr);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.out.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql)
{
int result=0;
try{
conn = DriverManager.getConnection(connStr);
stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
}
catch(SQLException ex){
System.out.println(ex.getMessage());
}
return result;
}
public void close()
{
try{
stmt.close();
conn.close();
}
catch(SQLException ex){
System.out.println(ex.getMessage());
}
}
} 展开
import java.sql.*;
public class DBBean
{
private String driverStr = "sun.jdbc.odbc.JdbcOdbcDriver";
private String connStr = "jdbc:odbc:mydbsource";
private Connection conn = null;
private Statement stmt = null;
public DBBean()
{
try {
Class.forName(driverStr);
}
catch(ClassNotFoundException ex) {
System.out.println(ex.getMessage());
}
}
public void setDriverStr(String dstr)
{
driverStr=dstr;
}
public void setConnStr(String cstr)
{
connStr=cstr;
}
public ResultSet executeQuery(String sql)
{
ResultSet rs = null;
try {
conn = DriverManager.getConnection(connStr);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.out.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql)
{
int result=0;
try{
conn = DriverManager.getConnection(connStr);
stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
}
catch(SQLException ex){
System.out.println(ex.getMessage());
}
return result;
}
public void close()
{
try{
stmt.close();
conn.close();
}
catch(SQLException ex){
System.out.println(ex.getMessage());
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询