Boby
Boby

Reputation: 1202

Create java connection to sql server 2008

GOod day, I just learning java about 2 days from internet. Now, i'm trying to open connection with my database but i having a problem.

java.sql.SQLException: No suitable driver found for jdbc:sqlserver://192.168.0.222;user=sa;password=N4ughty123456

here is my script .

  private void kuybtnActionPerformed(java.awt.event.ActionEvent evt) {                                       
        String nameval = utext.getText();
        String passval = ptext.getText();
        String ipval   = iptext.getText();

        String dbURL = "jdbc:sqlserver://"+ipval+";user="+nameval+";password="+passval+"";
        Connection conn;
        try {
            conn = DriverManager.getConnection(dbURL);
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (conn != null) {
            System.out.println("Connected");
        }
    }    

how can i fix this ? thanks in advance

Upvotes: 0

Views: 36

Answers (1)

André
André

Reputation: 172

as already mentioned the jdbc driver has to be on the classpath, also don't forget to close that connection.. like Closing Database Connections in Java

Upvotes: 1

Related Questions