连接数据库的问题
DBConn.javapackage test;
import java.sql.*;
public class DBConn{
String driverName,url,name,pwd;
Connection conn;
public DBConn(){
driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver";
url="jdbc:microsoft:sqlserver://localhost:1433; DatebaseName=test";
name="sa";
pwd="lszone";
}
public Connection get() throws Exception{
Class.forName(driverName);
conn=DriverManager.getConnection(url,name,pwd);
return conn;
}
public static void main(String args[]) throws Exception{
Connection conn=new DBConn().get();
System.out.println(conn);
}
}
test.java
package test;
import java.sql.*;
public class test{
Connection conn;
public test() throws Exception{
conn=new DBConn().get();
}
public static void main(String args[]) throws Exception{
Connection conn=new test().conn;
String sql="select * from user";
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getString(1));
}
System.out.println(conn);
}
}
提示居然是user附近有语法错误,我换个表名msg提示居然是对象不存在,我确定我确实有test数据库并且其中有msg和user表