Step a diagram.

Source: Internet
Author: User
Tags stmt

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.