jdbc连接sybase,表名前要加数据库名吗?
代码如下:public static void main(String[] args){
try {
Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
String url ="jdbc:sybase:Tds:192.168.8.100:5000/vmphone";
Connection conn= DriverManager.getConnection(url, "sa","");
Statement stmt=conn.createStatement();
String sql="select * from mytest";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
System.out.println(rs.getString("username"));
}else{
System.out.println("noDate");
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
报错:
com.sybase.jdbc3.jdbc.SybSQLException: mytest not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output).
如果我这样写,请注意粗体部分:
try {
Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
String url ="jdbc:sybase:Tds:192.168.8.100:5000/vmphone";
Connection conn= DriverManager.getConnection(url, "sa","");
Statement stmt=conn.createStatement();
String sql="select * from vmphone.mytest";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
System.out.println(rs.getString("username"));
}else{
System.out.println("noDate");
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public static void main(String[] args){
try {
Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
String url ="jdbc:sybase:Tds:192.168.0.102:5000/mysybase";
Connection conn= DriverManager.getConnection(url, "sa","");
Statement stmt=conn.createStatement();
String sql="select * from test_myuser";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
System.out.println(rs.getString("name"));
}else{
System.out.println("noDate");
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
首先可以确认的是不需要加数据库名的url中就已经包含了数据库名
用你的代码测试了下我这边没问题
页:
[1]