NetBeans Forums

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

Problem connecting NetBeans IDE 6.8 with SQL Server 2008

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



Joined: 27 Jan 2011
Posts: 6

PostPosted: Mon Feb 07, 2011 11:59 am    Post subject: Problem connecting NetBeans IDE 6.8 with SQL Server 2008 Reply with quote

I am using sqljdbc4.jar for connecting NetBeans 6.8 with SQL Server 2008. (I am using jdk 1.6 and jre 6)
I have added sqljdbc4.jar in the libraries folder of my Web Application Project.

Here is my code:- (Check.jsp)

<html>
<%@page language="java" %>
<%@ page import="java.sql.*" %>
<head>
</head>

<body bgcolor="#ECF4FC">
<% out.println("1");
String usrn,psswd;
usrn = request.getParameter("reg_username");
psswd = request.getParameter("reg_password");
String connectionUrl = "jdbc:sqlserver//localhost:1433;" +
"databaseName=userdb;user=Kunal-PC\\Kunal;password=null";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
out.println("2");
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
out.println("3");
con = DriverManager.getConnection(connectionUrl);
out.println("4");
stmt = con.createStatement();
out.println("5");
// Create and execute an SQL statement that returns some data.
stmt.executeUpdate("INSERT INTO usertb values('"+usrn+"','"+psswd+"')");
out.println("6");
rs = stmt.executeQuery("SELECT * FROM usertb");
out.println("7");
// Iterate through the data in the result set and display it.
while(rs.next())
{
String s11= rs.getString(1);
String s21= rs.getString(2);
out.println(s11);
out.println(s21);
out.println("8");
}
}

// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
%>

</body>
</html>

Output:
The Screen shows only 1 2 3... (separated by a space instead of a line)

which means there is a problem with con=DriverManager.getConnection(connectionUrl);
so something is wrong with my connectionUrl !!!

I am also including the screenshot of SQL Management Studio so that you guys can tell if I need to change something in connectionURL.

Also do I need to set classpath in NetBeans ??



SQL Management Studio.jpg
 Description:
 Filesize:  91.96 KB
 Viewed:  3419 Time(s)

SQL Management Studio.jpg


Back to top
pradyut



Joined: 05 Mar 2010
Posts: 7

PostPosted: Mon Feb 07, 2011 2:28 pm    Post subject: Reply with quote

connection pooling with sql server and more...
http://msdn.microsoft.com/en-us/library/ms378672.aspx
Back to top
pradyut



Joined: 05 Mar 2010
Posts: 7

PostPosted: Mon Feb 07, 2011 2:33 pm    Post subject: Reply with quote

u r connecting sql server with windows authentication??? if then how come jdbc will know about windows authentication??? use sql server authentication...
Back to top
smarty3010



Joined: 27 Jan 2011
Posts: 6

PostPosted: Mon Feb 07, 2011 2:52 pm    Post subject: Reply with quote

i installed SQL Management Studio and SQL Server 2008 BOTH by using windows authentication only....

Do i have to uninstall both of them and then install by using mixed mode authentication?

Is there anyway to configure them?
Back to top
smarty3010



Joined: 27 Jan 2011
Posts: 6

PostPosted: Mon Feb 07, 2011 3:20 pm    Post subject: Reply with quote

I changed the authentication mode by following the procedure given at:-
http://msdn.microsoft.com/en-us/library/ms188670.aspx

I can now access SQL Management Studio using sql authentication Cool

String connectionUrl = "jdbc:sqlserver//localhost:1433;" +
"databaseName=userdb;user=sa;password=****";
(not showing password for security reasons) Wink

But the still the same output !!!!!!!!!!!!!! Sad (no errors though)
How can I verify that port no. used is 1433?
Do I need to set classpath in NetBeans ??
Back to top
smarty3010



Joined: 27 Jan 2011
Posts: 6

PostPosted: Tue Feb 08, 2011 2:39 pm    Post subject: Reply with quote

Missed a colon after sqlserver in the earlier string !!!!! Shocked
Now its working perfect. Smile

Thanks pradyut for advising to switch to sql authentication mode.
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