当前位置: 技术问答>java相关
关于jdbc连接不上的问题
来源: 互联网 发布时间:2015-08-04
本文导语: 我用jdbc连接本地的一个access 的odbc数据源。 String os = "data:"; try{ Connection con = DriverManager.getConnection("jdbc.odbc.jdbcodbc.acc"); Statement stmt = con.createStatement(); String query = "Select ...
我用jdbc连接本地的一个access 的odbc数据源。
String os = "data:";
try{
Connection con = DriverManager.getConnection("jdbc.odbc.jdbcodbc.acc");
Statement stmt = con.createStatement();
String query = "Select name from user";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
String s = rs.getString("name");
os += s;
}
}
catch(Exception ee){}
JOptionPane.showMessageDialog(null,os);
我确认数据表user中有两行数据。为什么输出的送是data:
String os = "data:";
try{
Connection con = DriverManager.getConnection("jdbc.odbc.jdbcodbc.acc");
Statement stmt = con.createStatement();
String query = "Select name from user";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
String s = rs.getString("name");
os += s;
}
}
catch(Exception ee){}
JOptionPane.showMessageDialog(null,os);
我确认数据表user中有两行数据。为什么输出的送是data:
|
String os = "data:";
try{
Connection con = DriverManager.getConnection("jdbc.odbc.jdbcodbc.acc");
Statement stmt = con.createStatement();
String query = "Select name from user";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
String s = rs.getString("name");
os += s;
}
}
catch(Exception ee){
System.out.println("ocjbException:"+ee.toString());
}
在运行一下你的程序,然后看看log文里面,是否出现了异常。
try{
Connection con = DriverManager.getConnection("jdbc.odbc.jdbcodbc.acc");
Statement stmt = con.createStatement();
String query = "Select name from user";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
String s = rs.getString("name");
os += s;
}
}
catch(Exception ee){
System.out.println("ocjbException:"+ee.toString());
}
在运行一下你的程序,然后看看log文里面,是否出现了异常。
|
试一下这样如何?
String os = "data:";
try{
Connection con = DriverManager.getConnection("jdbc.odbc.jdbcodbc.acc");
Statement stmt = con.createStatement();
String query = "Select name from user";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
String s = rs.getString("name");
os += s;
}
System.out.println(os);//
JOptionPane.showMessageDialog(null,os);//
}
catch(SQLException ee){}//
String os = "data:";
try{
Connection con = DriverManager.getConnection("jdbc.odbc.jdbcodbc.acc");
Statement stmt = con.createStatement();
String query = "Select name from user";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
String s = rs.getString("name");
os += s;
}
System.out.println(os);//
JOptionPane.showMessageDialog(null,os);//
}
catch(SQLException ee){}//
|
把Connection改成这个试试:Connection con = DriverManager.getConnection("jdbc.odbc.jdbcodbc.acc","","");
|
写的applet ?!
|
安全验证的问题