NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

getting database connection in netbeans

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
ravidasineni



Joined: 25 Nov 2009
Posts: 2

PostPosted: Fri Nov 27, 2009 3:57 am    Post subject: getting database connection in netbeans Reply with quote

I am staring a new project with swing application framework in netbeans 6.5 in that i selected newproject->java - java desktop application - basic application-> finish.
when opening the project i saw three classes about,view,app.In view class
i started doing my project in that class i take two textboxes and one button.the
textboxes names are usernamee and password.and a button name is submit.from that
class i connect a database connection to SQLServer 2005.In my code i loaded
driver successfully but not getting connection. In libraries i add sqljdbc.jar
file also.please help me

//code under the button

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

String user = username.getText();
String pass = password.getText();

System.out.println("username " + user);
System.out.println("password "+pass);


try {
//connecting database


Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

System.out.println("driver loaded........");



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='" + user + "' and Password='" + pass + "'");
System.out.println("resultset created.");
if (rst.next())
{
db_username = rst.getString("UserName");
db_password = rst.getString("Password");
System.out.println("retrieving username,password.");

}

if (user.equals(db_username))
{
if (pass.equals(db_password))
{

NewJFrame appframe = new NewJFrame();
appframe.setVisible(true);

}
}
} catch (Exception e)
{
e.printStackTrace();
}
}



output:
//entered textboxes username and password
username:ravi
password:ravi

driver loaded..... after that process is running only and structed the form

and connection is not getting plz help me
Back to top
Mark Wade
Posted via mailing list.





PostPosted: Sat Nov 28, 2009 12:29 am    Post subject: getting database connection in netbeans Reply with quote

Quote:
>> con = DriverManager.getConnection("jdbc:sqlserver://java04:1433;databaseName=appforum;userName=sa");Your not including a password in your getConnection(String url,
Back to top
Melongo Annabel
Posted via mailing list.





PostPosted: Mon Nov 30, 2009 5:47 pm    Post subject: getting database connection in netbeans Reply with quote

Ravi,
Try adding the db driver's in the project's runtime classpath as well: http://netbeans.org/kb/55/using-netbeans/deploy.html#69958


From: ravidasineni <address-removed>
To: address-removed
Sent: Thu, November 26, 2009 9:57:41 PM
Subject: [nbusers] getting database connection in netbeans

I am staring a new project with swing application framework in netbeans 6.5 in that i selected newproject->java - java desktop application - basic application-> finish.
when opening the project i saw three classes about,view,app.In view class
i started doing my project in that class i take two textboxes and one button.the
textboxes names are usernamee and password.and a button name is submit.from that
class i connect a database connection to SQLServer 2005.In my code i loaded
driver successfully but not getting connection. In libraries i add sqljdbc.jar
file also.please help me

//code under the button

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

String user = username.getText();
String pass = password.getText();

System.out.println("username " + user);
System.out.println("password "+pass);


try {
//connecting database


Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

System.out.println("driver loaded........");



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='" + user + "' and Password='" + pass + "'");
System.out.println("resultset created.");
if (rst.next())
{
db_username = rst.getString("UserName");
db_password = rst.getString("Password");
System.out.println("retrieving username,password.");

}

if (user.equals(db_username))
{
if (pass.equals(db_password))
{

NewJFrame appframe = new NewJFrame();
appframe.setVisible(true);

}
}
} catch (Exception e)
{
e.printStackTrace();
}
}



output:
//entered textboxes username and password
username:ravi
password:ravi

driver loaded..... after that process is running only and structed the form

and connection is not getting plz help me
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo