当前位置: 技术问答>java相关
数据库连接问题(access),求助!
来源: 互联网 发布时间:2015-08-17
本文导语: 下面的有问题,谁能帮我改改或给我源代码。 import java.sql.*; public class faq{ String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; String sConnStr = "jdbc:odbc:faq"; Connection conn = null; public faq(){ Class.forName(sDBDriver); ...
下面的有问题,谁能帮我改改或给我源代码。
import java.sql.*;
public class faq{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq";
Connection conn = null;
public faq(){
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.out.println("faq():"+e.getMessage());
}
}
public ResultSet excuteQuery(String sql){
rs = null;
try{
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeUpdate(sql);
}
catch(SQLException ex){
System.out.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
import java.sql.*;
public class faq{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq";
Connection conn = null;
public faq(){
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.out.println("faq():"+e.getMessage());
}
}
public ResultSet excuteQuery(String sql){
rs = null;
try{
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeUpdate(sql);
}
catch(SQLException ex){
System.out.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
|
我帮你调好了。文件名为faq.java
你自己再试一下。OK!
import java.sql.*;
public class faq
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq";
Connection conn = null;
public faq()
{ try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.out.println("faq():"+e.getMessage());
}
}
public ResultSet excuteQuery(String sql)
{
ResultSet rs = null;
try{
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex){
System.out.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
}
你自己再试一下。OK!
import java.sql.*;
public class faq
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq";
Connection conn = null;
public faq()
{ try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.out.println("faq():"+e.getMessage());
}
}
public ResultSet excuteQuery(String sql)
{
ResultSet rs = null;
try{
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex){
System.out.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
}
|
在Connection conn = null;下加 ResultSet rs = null;
|
conn = DriverManager.getConnection(sConnStr,username,password);//用户名及密码,如果没有设置,则为空conn = DriverManager.getConnection(sConnStr,“”,“”);
|
数据库链接的建立与关闭
数据库链接的建立与关闭
已经建立了与数据库faq_access的链接
已经关闭与数据库faq_access的链接
|
你的错误信息呢?
|