Jbuilder2006 Connection sql

Source: Internet
Author: User
Server|server2000|sql

My development environment is: jdk1.5+jbuilder2006+sql_server2000 SP3

First, the configuration environment, including the download jdbc FRO microsft sql_server2000 Driver (under the Microsoft Official website, is the SP3 version, here will not write the specific address, the network is quite many, but the attention version, I under the SP3). After the download is found EXE file, double-click the installation. Default installation directory: C:\Program Files\Microsoft SQL Server Driver for JDBC, where C:\Program Files\Microsoft SQL Server, Driver for The three extensions under the Jdbc\lib directory are. Jar is the drive we want. Then configure the environment variables:

Add the following statement to the CLASSPATH environment variable:

       
        
         
        C:\Program Files\Microsoft SQL Server Driver for Jdbc\lib\msbase.jar; C:\Program Files\Microsoft SQL Server Driver for Jdbc\lib\mssqlserver.jar; C:\Program Files\Microsoft SQL Server Driver for Jdbc\lib\msutil.jar;
       
        

If you have the correct configuration of the JDK environment variables on the machine should have classpath this environment variable, if not the new one.

In fact, the purpose of the environment variable is to allow the system to find the driver, if not, execution of the following section of code will produce can not find the driver exception, resulting in the program can not be executed.

After doing these things, I used ultraedit This software first wrote the connection database code to test, the code is as follows:

 
       
        /* Try to connct sql_server data Base*/import java.sql.*;p ublic class sql_db_test{connection con; Statement STA; ResultSet rs; String Sql_driver; String Sql_url; String user; String pwd;public sql_db_test () {sql_driver= "com.microsoft.jdbc.sqlserver.SQLServerDriver";//Driver sql_url= "JDBC: Microsoft:sqlserver://localhost:1433;databasename=manage "//Statement one, where manage is the name of the database to be accessed user=" Xiaolin "; You want to access the database username pwd= "123456";//Password init () to access the database;} public void init () {try{class.forname (sql_driver);//Load Driver System.out.println ("Driver is OK"); con= Drivermanager.getconnection (SQL_URL,USER,PWD); SYSTEM.OUT.PRINTLN ("Connection is OK"); sta=con.createstatement (); Rs=sta.executequery ("the SELECT * from clothing sheet");/ Executequerywhile (Rs.next ()) System.out.println (rs.getstring ("style"));} catch (Exception e) {e.printstacktrace ();//printstacktrace ();}}
     public static void Main (string[] args) {new sql_db_test ();}} 
       

After you save the top code, execute it in the command prompt.

Javac Sql_db_test.java//Compile normal pass

Java sql_db_test//Generates an exception, as follows

 
        
          Driver is okjava.sql.SQLException: [Microsoft][sqlserver driver for Jdbc]error establishing  Et. At Com.microsoft.jdbc.base.BaseExceptions.createException (Unknown Source) at Com.microsoft.jdbc.base.BaseExceptions.getException (Unknown Source) at Com.microsoft.jdbc.base.BaseExceptions.getException (Unknown Source) at Com.microsoft.jdbc.sqlserver.tds.tdsconnection.<init> (Unknown Source) at Com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open (Unknown Source) at Com.microsoft.jdbc.base.BaseConnection.getNewImplConnection (Unknown Source) at Com.microsoft.jdbc.base.BaseConnection.open (Unknown Source) at Com.microsoft.jdbc.base.BaseDriver.connect (Unknown Source) at Java.sql.DriverManager.getConnection (drivermanager.java:523) at Java.sql.DriverManager.getConnection ( drivermanager.java:171) at Dbtest.init (dbtest.java:32) at dbtest.<init> (dbtest.java:25) at DbTest.main ( DBTEST.JAVA:46) Press any key to continue ... 
         

The main reason for the top error is that the default database server port 1433 is not open and cannot be connected directly.

At this point you enter a command at the command prompt: Netstat–an to see if there is any tcp:0.0.0.0:1433, if not, it must be because the database server port 1433 port is not open. At this time you need to download sql_serve20000 SP3 patch, download installation will find that 1433 ports have been opened, and then execute the program, successfully completed.

The above is performed on a computer, and then I put the above program to another computer (think the client, ip:192.168.1.2), connect two computers with a direct connection, so that the original computer becomes a database server (ip:192.168.1.1). And the localhost in the statement one of the program is changed to 192.168.1.1, the other unchanged.

Establishing socket exception was generated after execution

Later, the check found that the other computer was not visible in the Network Neighborhood, then reset the net and open the Guest user to release permissions.

Make the other computer appear in your network Places, and then execute the program again.

Next, I began to join the Jbuilder2006, I wrote a database in the JBuilder of the class, the other places to make related changes, because the code too much, can not be in these. Just write out the question here:

Unexpectedly, after all the modifications, the software ran with the following exception:

 
        
          Java.lang.ClassNotFoundException:com.microsoft.jdbc.sqlserver.SQLServerDriver at Java.net.urlclassloader$1.run ( Unknown Source) at Java.security.AccessController.doPrivileged (Native method) at Java.net.URLClassLoader.findClass (U Nknown source) at Java.lang.ClassLoader.loadClass (Unknown source) at Sun.misc.launcher$appclassloader.loadclass (unkn Own source) at Java.lang.ClassLoader.loadClass (Unknown source) in Java.lang.ClassLoader.loadClassInternal (Unknown so Urce at JAVA.LANG.CLASS.FORNAME0 (Native method) at Java.lang.Class.forName (Unknown Source) at Sql_db_test.init (S
       ql_db_test.java:21) at sql_db_test.<init> (sql_db_test.java:16) at Sql_db_test.main (Sql_db_test.java:36) 
        

That's not to say the driver can't find it?? Why?? Later on the internet to find out that their ignorance, it is too much food!!! Originally in JBuilder also have to set the path of the driver, set the method as follows:

First, open JBuilder, choose Tools-->configure-->libraries.

Second, then select New in the list box on the left, fill in: Name:sql,location:user home, then click Add,

Add directory C:\Program Files\Microsoft SQL Server Jdbc\lib, OK.

Third, Project-->prject properties-->paths-->required Libraries-->add

Join the user home/sql you just added to determine

Four, enterprise-->enterprise setup-->database drivers-->add, add user Home/sql,

After adding the Sql.config is displayed in the list box, OK, reboot JBuilder

Five, Tools-->database

Pilot-->view-->options-->drivers-->add

Fill in

       
        
         
        Driver Class:com.microsoft.jdbc.sqlserver.SQLServerDriver Simple Url:microsoft:sqlserver://localhost:1433;d Atabasename=mybase
       
        

After confirming, Tools-->database Pilot-->new's driver chose

       
        
         
        Com.microsoft.jdbc.sqlserver.SQLServerDriver
       
        

Fill in the URL:

       
        
         
        microsoft:sqlserver://server IP address or host name: 1433;databasename= database name
       
        

Click OK, double-click or click + to enter the username and password of SQL database, and then complete the link between JB and SQL!



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.