Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I want to use databases created in sql server in netbeans , i am bit confuse in the process their are many programs and stored procedures found on sites but i could not found step by step procedure for set connection. i want every step where to write code and procedures for connection , anyone please help me .
Posted
Updated 27-Jun-16 5:54am
Comments
Kornfeld Eliyahu Peter 12-May-15 9:07am    
Are you talking about a Java project?
Member 11543226 13-May-15 0:59am    
yes im talking about java project
Afzaal Ahmad Zeeshan 27-Jun-16 12:19pm    
Get the SQL Server drivers for Java and then connect from Java to SQL Server.

I don't think you want to connect it to netbeans. But you may want to connect it to your Java program. Take a look at http://docs.oracle.com/javase/tutorial/jdbc/index.html[^].
 
Share this answer
 
Comments
Stack Holder 27-Jun-16 11:46am    
This link is not so good for the Member 11543226.
Richard MacCutchan 27-Jun-16 12:01pm    
What are you talking about? This post is over a year old.
Stack Holder 27-Jun-16 12:11pm    
For any misunderstanding,i am saying sorry to you.
Stack Holder 27-Jun-16 12:11pm    
It maybe, but the link you have posted is not matching to the exact demand of the Member 11543226.
Richard MacCutchan 27-Jun-16 12:20pm    
Since OP never responded, you have no basis for your statements. And in future please do not post in old questions, it is most unlikely that the OP is any longer interested.
Please try

Java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
String name=jTextField1.getText();
String password=jTextField2.getText();
jLabel3.setText(name+" "+password);
 
    try {
            
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            
            
            Connection conn = DriverManager.getConnection("jdbc:sqlserver://DBASE\\SQLEXPRESS;DatabaseName=StackHolder", "sa", "dbase");

            Statement statement = conn.createStatement();

            PreparedStatement prep = conn.prepareStatement("INSERT INTO Users(name, pass) VALUES(?, ?)");

            prep.setString(1, name);
            prep.setString(2, password);
            prep.executeUpdate();

            ResultSet resultSet = statement.executeQuery("SELECT name FROM Users");

            while(resultSet.next()){

            System.out.println("name: " + resultSet.getString("name"));
        
            }

            conn.close();
         
}

    catch (Exception ex) {
                            
                    System.out.println(ex);       
}

// TODO add your handling code here:
    }    
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900