Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-24-2009, 06:56 AM
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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-24-2009, 07:04 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
Fubarable is on a distinguished road
Default
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.
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with connecting to another computers database rakesh_n_mehta Database 0 12-24-2008 11:35 AM
Problem in connecting to database.. Preethi New To Java 10 06-26-2008 06:53 AM
problem in connecting to mysql database nancyv Java Servlet 6 04-02-2008 12:33 PM
Problem connecting to my Database using Java javaneed New To Java 3 08-13-2007 10:35 AM


All times are GMT +2. The time now is 05:28 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org