Current location - Quotes Website - Team slogan - Unable to connect to JDBC SQL server, how to solve it?
Unable to connect to JDBC SQL server, how to solve it?
One problem to be inserted here is the port occupied by the database.

There are two ways to do this.

Method 1:

Open the database, create a new query, enter the code,

You can see that the port number is 1 1588.

Method 2:

Here I also want to insert a problem I have encountered, that is, the TCP dynamic port of IPALL is 0,,, and mine is 0,,,

The problem is that the TCP/IP protocol of SQLNAME is not open.

The solution is to open it and then restart the service of SQLNAME, which is necessary, otherwise the change will be invalid.

You can also use cmd's netstat -an command to see if the port is in use.

You can see normal use.

Try again after writing the URL? Catch still reported an error, and the problem was discovered after various Baidu. So I downloaded SQL server 2008? But the website says mysql? These two databases are not a family. . .

As a result, I downloaded the jar of SQL again, rejoined the project, and rewritten the code.

【java】? View the plain? copy

class . forname(" com . Microsoft . SQL server . JDBC . SQL server driver "); ?

String? Website? =? " JDBC:SQL server:// 127 . 0 . 0 . 1: 1 1588; DatabaseName = test 728 "; ?

String? User? =? "sa"; ?

String? Password? =? " 123456"; ?

Contact? A scam? =? Drivermanager. getconnection (URL, user, password); ?

Try here? Catch is nothing unusual. Let's try to connect to the database and insert a table.

【java】? View the plain? copy

Try it? {?

class . forname(" com . Microsoft . SQL server . JDBC . SQL server driver "); ?

String? Website? =? " JDBC:SQL server:// 127 . 0 . 0 . 1: 1 1588; DatabaseName = test 728 "; ?

String? User? =? "sa"; ?

String? Password? =? " 123456"; ?

Contact? A scam? =? Drivermanager. getconnection (URL, user, password); ?

String? sql? =? "Insert? Become? dbo。 StuInfo? (User name, password, gender, age)? Values ('Zhang San',' 123',' male', 22) "; ?

Statement? sta? =? con . create statement(); ?

sta . execute update(SQL); ?

con . close(); ?

}? Catch? (SQLException? e)? {?

//? TODO:? Handle? Exceptions?

system . out . println(" error "); ?

}? Catch? (ClassNotFoundException? e)? {?

//? Todo? Automatically generated? Catch? Shielding

e . printstacktrace(); ?

System.out.println("class? Error "); ?

}?

There is no exception in compiling and running.

These are my own problems, quite a lot.

Welcome to correct me.