在线等....sqlserver2005:查询时如何能去掉数据库名?
问题如题:代码如下
private static void testDatabase(){ String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; String dbUrl = "jdbc:sqlserver://192.168.1.110:1433;DatabaseName=testDataBase"; String userName = "sa"; String pwd = "123456"; try { Class.forName(driverName); Connection conn = DriverManager.getConnection(dbUrl,userName,pwd); System.out.println("连接成功"); String sql = "select * from CM_COMPETENCE";//错误sql语句 String sql = "select * from testDataBase.CM_COMPETENCE";//正确sql语句 PreparedStatement ps = conn.prepareStatement(sql); ps.execute(); conn.close(); } catch (Exception e) { e.printStackTrace(); System.out.println("连接失败"); } }