when you perform a JDBC Direct operations database :
We need to carry out a guide to the project (the introduction of "Msbase.jar" "Mssqlserver.jar" "Msutil.jar" the three packages, the specific practice is)
Select the item that we want to import the package by hand, right click on the list of columns, select Properties, then select Java bukid Path in the panel, then check Add External Jars
, and finally select the package we want to import.
Graphic:
(1) (2)
This will import the required three packages into ..... But here comes the question again,
Class.forName ("Com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connect to SQL
ct = drivermanager.getconnection ("Jdbc:microsoft:sqlserver://localhost:1433;databasename=demo_1", "sa", " 869261636123 ");
PS = ct.preparestatement (SQL);
rs = Ps.executequery ();
When the code runs here, our most common problem is this error message][sqlserver the Driver for jdbc]error establishing socket.
Encounter this hint: say, that what, our socket failed to build, here is likely to be the port problem (General SQL Port is 1433 but there is likely to be a problem with other ports)
So we might as well check our port connectivity issues: Ctrl + R--cmd---> netstat-an---> Get what we're looking for
So we just need to change the port number from 1433 to 1434 on the line,
ct = drivermanager.getconnection ("Jdbc:microsoft:sqlserver://localhost:1434;d atabasename=demo_1", "sa", " 869261636123 ");
Then the problem is solved by the edge!!! At this time is not also think of the king of the steamer of the steaming kui of laughter? hahaha ha ha haha haha ~~~~! End
Of course, when we first configure the environment, the data will appear garbled. .... Well, of course, we'll know that this is due to the fact that the database and our compiler encode different formats, so we generally take some of these statements to deal with such problems:
For example: (rs.getstring (i)). GetBytes ("GBK"), "gb2312"); It's all right!
The Java Operations database appears (][sqlserver Driver for jdbc]error establishing socket.) The problem is the solution