2013年12月1日星期日

Tried many times , or not

public class MySqlDemo {

public static void main (String [] args) {
/ / Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc: sqlserver :/ / localhost: 1433; DatabaseName = db_mysise";
String user = "root";
String password = "12345";
Connection conn = null;
Statement stat = null;
try {
Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection (url, user, password);
stat = conn.createStatement ();
String sql = "select * from student";
ResultSet rs = stat.executeQuery (sql);
System.out.println (" Student ID \ t \ t" + " name \ t" + " sex \ t" + " Age \ t" + " professional \ t \ t \ t" ; + " quarters " ) ;
while (rs.next ()) {
String num = rs.getString (" study" ) ;
String name = rs.getString (" name " ) ;
String sex = rs.getString (" gender" ) ;
String age = rs.getString (" age" ) ;
String major = rs.getString (" Professional " ) ;
String dorm = rs.getString (" quarters " ) ;
System.out.println ("" + num + "\ t" + name + "\ t" + sex + "\ t" + age + "\ t" + major + " ; \ t "+ dorm);
}
rs.close ();
stat.close ();
conn.close ();
} catch (Exception e) {
e.printStackTrace ();
}
}
}
results
com.microsoft.sqlserver.jdbc.SQLServerException: to host a TCP / IP connection failed. java.net.ConnectException: Connection refused: connect
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError (Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper (Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover (Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect (Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect (Unknown Source)
at java.sql.DriverManager.getConnection (DriverManager.java: 582)
at java.sql.DriverManager.getConnection (DriverManager.java: 185)
at com.sise.testdemo.MySqlDemo.main (MySqlDemo.java: 32)
------ Solution ------------------ --------------------------
mssql you connect to the machine ?

looks like a database connection is not on
------ Solution ------------------------------ --------------
TCP / IP fail ?
you execute:
telnet localhost 1433
see what results ? Is not your port , right? Or the database does not start ?

------ Solution ------------------------------------ --------
reinstall tcpip
------ Solution -------------------------- ------------------
this is obviously a connection to the database fails , sqlserver some service every start , you look for a look at the sqlserver configuration tool
- ----- Solution --------------------------------------------
SQLserver 2005?

In the Configuration Manager, the tcp / ip ban entry to start. Restart the server
------ For reference only ---------------------------------------
yesterday changed the configuration and restart the service after the connection is successful , the code is tested successful. But today, landing a look at the database , with a window to verify whether or not sql server database to verify all landed , what ah

没有评论:

发表评论