View Single Post
  #1 (permalink)  
Old 11-24-2009, 06:56 AM
ravidasineni ravidasineni is offline
Member
 
Join Date: Nov 2009
Posts: 4
Rep Power: 0
ravidasineni is on a distinguished road
Default problem with connecting database
I am staring a new project with swing application framework in netbeans in that i selected newproject->java - java desktop application - basic application-> finish.

In that i started doing project in a view class, in that class i take two textboxes and one button to design login page.From that class i connect a database connection to check the textboxes values.the driver is loaded successfully and connection is not connected to database in that class only.

From that project when i take a new class in that i can connect database successfully and retrive the values.I add all libraries and jar files.plz check the following code and help me.I wrote the following code under the button.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// getting textbox values.

String us = u.getText();
String vs = p.getText();

System.out.println("username " + us);
System.out.println("password "+vs);
// values retrived successfully.

try {
//connecting database


Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
System.out.println("driver loaded........");
// driver loaded successfully.

// from hear process is not done...
con = DriverManager.getConnection("jdbc:sqlserver://java04:1433;databaseName=appforum;userName=sa");



stmt = con.createStatement();
System.out.println("statement created.");
rst = stmt.executeQuery("select userName,Password from SwingsUser where UserName='" + us + "' and Password='" + vs + "'");
System.out.println("resultset created.");
if (rst.next()) {
r = rst.getString("UserName");
rs = rst.getString("Password");
System.out.println("retrieving username,password.");
}

if (us.equals(r)) {
if (vs.equals(rs)) {

//going to next page

j = new NewJFrame();
j.setVisible(true);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}



output:

username:ravi
password:ravi

driver loaded..... after that process is running and structed the form
Reply With Quote