当前位置: 技术问答>java相关
servlet与access数据库连接的问题?
来源: 互联网 发布时间:2015-11-13
本文导语: 我做了一个数据库,不过我的连接总是不对。下面是原代码:请各位帮忙看看。String strDriver="sun.jdbc.odbc.JdbcOdbcDrvier"; String url="jdbc:odbc:accessdata"; String sqlstm="SELECT Empno,Name,Jobtitle FROM Employee"; query(strDriver,url,props,sql...
我做了一个数据库,不过我的连接总是不对。下面是原代码:请各位帮忙看看。String strDriver="sun.jdbc.odbc.JdbcOdbcDrvier";
String url="jdbc:odbc:accessdata";
String sqlstm="SELECT Empno,Name,Jobtitle FROM Employee";
query(strDriver,url,props,sqlstm,out);
out.println("");
out.println("");
out.flush();
}
private boolean query (String driverName,String connectionURL,java.util.Properties props,String query, java.io.PrintWriter out)
{
boolean ret=true;
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
long startMs=System.currentTimeMillis();
int rowCount=0;
try{
Class.forName(driverName);
con=DriverManager.getConnection(connectionURL,props);
stmt=con.createStatement();
rs=stmt.executeQuery(query);
rowCount=formatTable(rs,out);
}
catch(Exception ex)
{
out.println("异常");
ex.printStackTrace(out);
ret=false;
}
String url="jdbc:odbc:accessdata";
String sqlstm="SELECT Empno,Name,Jobtitle FROM Employee";
query(strDriver,url,props,sqlstm,out);
out.println("");
out.println("");
out.flush();
}
private boolean query (String driverName,String connectionURL,java.util.Properties props,String query, java.io.PrintWriter out)
{
boolean ret=true;
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
long startMs=System.currentTimeMillis();
int rowCount=0;
try{
Class.forName(driverName);
con=DriverManager.getConnection(connectionURL,props);
stmt=con.createStatement();
rs=stmt.executeQuery(query);
rowCount=formatTable(rs,out);
}
catch(Exception ex)
{
out.println("异常");
ex.printStackTrace(out);
ret=false;
}
|
就这么多吗?你的boolean没有返回,还有,你的这个东西做什么的?怎么看它都没什么用.
|
同意楼上的,还有就是,你传入的参数也有问题:
query(strDriver,url,props,sqlstm,out);
query(strDriver,url,props,sqlstm,out);
|
you should write query(strDriver,url,yourpassword);