Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Connecting To Sql Server

Recommended Posts

I get the following error while trying to connect to SQL Server using JSP.Login failed for user 'prashanti'. Reason: Not associated with a trusted SQL Server connection.My code is as follows:<html><head></head><body><%@ page import="java.sql.*" %><% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); %><% Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433","prashanti","prashanti"); Statement stmt = conn.createStatement();ResultSet columns = stmt.executeQuery("select * from employee");while(columns.next()){String name = columns.getString("name");String address = columns.getString("address");%><%=name%><%}%></body></html>Any help will be appreciated.Thanks,

Share this post


Link to post
Share on other sites

Login failed for user 'prashanti'. Reason: Not associated with a trusted SQL Server connection.

Okay. I am assuming this isn't on Xisto because as far as I know we only get MySQL and postgress databases here.

 

If you have access to the sql server and are allowed to change settings you have to change the authentication mode in the SQL server properties from "Windows only" to "SQL Server and Windows". This is not a java/jsp problem, you would probably get that error with any app you make.

 

Hope this helps, otherwise google came up with quite a lot of results. Good luck.

Share this post


Link to post
Share on other sites

I'm using following sintax for connects to the Oracle database from JSP (Tomcat 5.0)

	DbConnectionPool dbpool;         dbpool = new DbConnectionPool(  "oracle.jdbc.driver.OracleDriver",                  "jdbc:oracle:thin:temp/temp@192.168.0.1:1521:temp",                  "",                  "");	Connection conn;	Statement stmt;         conn = (Connection)dbpool.getConnection(20000);         stmt = conn.createStatement();
and after this text u can use created statment for getting resultsets etc....

        ResultSet rs = stmt.executeQuery(        	"SELECT * " +  	"FROM table where param1 = '" +  	param1 + "' and  param2 = '" + param2 + " ' ");

Good luck with it... it's for oracle database but i thk creating connections is same in other driver...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.