首页上一页 1 下一页尾页 3 条记录 1/1页
访问不了SQL2005表。SQL应该怎么设置用户权限,访问表呢?
发表在Java图书答疑
2010-12-27
是否精华
是
否
版块置顶:
是
否
这是我的代码
SQL2005登录时服务器名称是Localhost 帐号sa 密码123
我的sql2005的截图:
[img src=http://links.imgup.cn/201012/27/20/47009_1293453867c6N0.jpg/img]
import java.sql.*;
import javax.sql.rowset.JdbcRowSet;
public class UseSqlClass {
public Connection conn=null;
public Connection getConnection()
{
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databasename=SqlTest";
String name="sa";
String password="123";
conn=DriverManager.getConnection(url,name,password);
if(conn!=null)
{
System.out.println("连接成功");
}
Statement statement=conn.createStatement();
statement.executeUpdate("insert into Tb_User values(null,'asdas','hjkh','sadf')");
conn.close();
System.out.println(":"+statement.getUpdateCount());
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
return conn;
} public static void main(String args[])
{
UseSqlClass useSqlClass=new UseSqlClass();
useSqlClass.getConnection();
}
}
错误信息:
连接成功
com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 'Tb_User' 无效。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StatementExecutionRequest.executeStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(Unknown Source)
at UseSqlClass.getConnection(UseSqlClass.java:18)
at UseSqlClass.main(UseSqlClass.java:34)
SQL2005登录时服务器名称是Localhost 帐号sa 密码123
我的sql2005的截图:
[img src=http://links.imgup.cn/201012/27/20/47009_1293453867c6N0.jpg/img]
import java.sql.*;
import javax.sql.rowset.JdbcRowSet;
public class UseSqlClass {
public Connection conn=null;
public Connection getConnection()
{
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databasename=SqlTest";
String name="sa";
String password="123";
conn=DriverManager.getConnection(url,name,password);
if(conn!=null)
{
System.out.println("连接成功");
}
Statement statement=conn.createStatement();
statement.executeUpdate("insert into Tb_User values(null,'asdas','hjkh','sadf')");
conn.close();
System.out.println(":"+statement.getUpdateCount());
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
return conn;
} public static void main(String args[])
{
UseSqlClass useSqlClass=new UseSqlClass();
useSqlClass.getConnection();
}
}
错误信息:
连接成功
com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 'Tb_User' 无效。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StatementExecutionRequest.executeStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(Unknown Source)
at UseSqlClass.getConnection(UseSqlClass.java:18)
at UseSqlClass.main(UseSqlClass.java:34)