Java.sql.SQLException: [Microsoft][sqlserver Driver for jdbc][sqlserver] use? ' (null) ' Lost? Reason: Not connected to the trusted SQL Server??。
Java.sql.SQLException: [Microsoft][sqlserver Driver for jdbc][sqlserver] use? ' Sa ' is lost?
Enating Scoke .....
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
Step a diagram.
Http://p.blog.csdn.net/images/p_blog_csdn_net/masuwen/EntryImages/20090405/1.JPG
Step b diagram.
Http://p.blog.csdn.net/images/p_blog_csdn_net/masuwen/EntryImages/20090405/2.JPG
Step c diagram.
Http://p.blog.csdn.net/images/p_blog_csdn_net/masuwen/EntryImages/20090405/3.JPG
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Java.sql.ResultSet;
Import java.sql.Statement;
/**
*
* @author Administrator
* @version 2009-4-5
* @deprecated
*/
public class Jdbctest {
public static void Main (string[] args) {
try {
String url = "Jdbc:microsoft:sqlserver://localhost:1433;databasename=aicdata";
MyDB as a database
String user = "sa";
String password = "";
Class.forName ("Com.microsoft.jdbc.sqlserver.SQLServerDriver")
. newinstance ();
Connection conn = drivermanager.getconnection (URL, user, password);
System.out.println ("Connection successful!");
Statement stmt = Conn.createstatement ();
ResultSet Rstt = Stmt.executequery ("Select *from users");
while (Rstt.next ()) {
System.out.print (Rstt.getint ("u_id") + "/t");
System.out.print (rstt.getstring ("u_name") + "/t");
System.out.print (rstt.getstring ("U_password") + "/t");
System.out.print (rstt.getstring ("U_password") + "/t");
System.out.print (rstt.getstring ("u_role") + "/t");
System.out.println ("n");
}
catch (Exception e) {
E.printstacktrace ();
}
}
}//end Jdbctest
Database
database name; Aicdata
database table name; Users
CREATE TABLE Users (
u_id int not NULL,
U_name varchar () not NULL,
U_password varchar () not NULL,
U_role varchar (30)
)
INSERT into MSW values (1, ' user1 ', 1111, ' admin ');
INSERT into MSW values (2, ' User1 ', 2111, ' admin ');
INSERT into MSW values (3, ' User1 ', 3111, ' admin ');
Good luck, I wish you 続 success.
Out of ...... ..........
Connection successful!
1 user1 1111 1111 1
2 manager1 2222 2222 2
3 user3 3333 3333 3