我有这个问题:
Connection conn = null;
stmt = conn.createStatement();
stmt.execute("SELECT * FROM school.users");
我从该查询中得到了结果。如果我尝试在java中实现以下代码来设置默认数据库:
stmt.execute("database school");
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
我有这个错误:
Exception-> [Teradata Database] [TeraJDBC 14.10.00.17] [Error 3807] [SQLState 42S02] Object 'users' does not exist
你能看出错在哪里吗?
答案 0 :(得分:1)
在网址中添加DATABASE参数并尝试。
例如。 url="jdbc:teradata://exampleDns/DATABASE=school"
我希望这就是你要找的东西
答案 1 :(得分:0)
试试这个:
Connection conn = null;
Statement stmt = null;
try{
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
}
catch(SQLException se){
se.printStackTrace();
finally{
stmt.close();
conn.close();
}
答案 2 :(得分:0)
如果您使用Statement的executeUpdate“方法”怎么办?
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
stmt.executeUpdate("database school");
ResultSet rs = stmt.executeQuery("SELECT * FROM users");