Results 1 to 2 of 2
Thread: problem with connecting database
- 11-24-2009, 05:56 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 4
- Rep Power
- 0
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
-
Duplicate thread. OP: please don't multipost. Choose the one best forum for your question and post it there. I've locked the other thread.
Thank you for your cooperation.
Similar Threads
-
problem with connecting to another computers database
By rakesh_n_mehta in forum JDBCReplies: 0Last Post: 12-24-2008, 10:35 AM -
Problem in connecting to database..
By Preethi in forum New To JavaReplies: 10Last Post: 06-26-2008, 05:53 AM -
problem in connecting to mysql database
By nancyv in forum Java ServletReplies: 6Last Post: 04-02-2008, 11:33 AM -
Problem connecting to my Database using Java
By javaneed in forum New To JavaReplies: 3Last Post: 08-13-2007, 09:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks