Forums Register Login

Please Help:Access to Sql Server from servlet

+Pie Number of slices to send: Send
when i try to access sql server database i get the following error. I think the problem is in the syntax....can anybody please let me know about this!!
Here's part of the code:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DbTest extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
// First, set things up.
// JDBC driver.
String dbDriverName = "sun.jdbc.odbc.JdbcOdbcDriver";
// Connection URL.
//String dbConnectionURL = "jdbc dbc ractice";
//use this for remote access!!
String dbConnectionURL="jdbc dbc:;DRIVER={SQL SERVER};SERVER=(http://info2.graphiced.com:1433);DATABASE=Northwind;UID=guest;PID=guest" ;

// Connection object.
Connection dbConnection = null;
// Statement object.
Statement dbStatement = null;
// SQL statement to execute.
String sqlStatement = "Select * from ORDERS";
// Result set object.
ResultSet dbResultSet = null;
// Start the servlet output.
PrintWriter out = resp.getWriter();
resp.setContentType("text/html");
out.println("<html><head><title>DB Test</title></head><body>");
out.println("<h1>Database Test</h1>");
// Start the db access code.
try {
// Create JDBC driver instance.
Class.forName(dbDriverName).newInstance();
// Create db connection.
dbConnection = DriverManager.getConnection(dbConnectionURL);
// Create Statement object.
dbStatement = dbConnection.createStatement();
// Execute the query.
dbResultSet = dbStatement.executeQuery(sqlStatement);
// Print column headers.
ResultSetMetaData rsMetaData = dbResultSet.getMetaData();
int colCount = rsMetaData.getColumnCount();
// Displays the results in a table.
// Start the table.
out.println("<table>");

and here's the error:
java.sql.SQLException: [unixODBC][Driver Manager]Data source name not found, and
no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:2458)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:3
20)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:163)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at DbTest.doGet(DbTest.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:715)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155
)
at com.sun.web.core.InvokerServlet.service(InvokerServlet.java:168)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155
)
at com.sun.web.core.Context.handleRequest(Context.java:414)
at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:139)
+Pie Number of slices to send: Send
"R R P",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
+Pie Number of slices to send: Send
The exception looks to be saying that your JDBC URL is not valid. To use the JDBC-ODBC bridge, you need to register the ODBC datasource. Start up ODBCAD32 (in the control panel, or in the system32 folder) and set up a system DSN so that mySQLServer points to northwind (or whatever).
Then use a URL like jdbc:odbc:mySQLServer, and pass the username and password to the getConnection statement.
I do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1613 times.
Similar Threads
Data source name not found and no default driver specified
SQL Server JDBC Connectivity Error
while inserting into database
JDBC on postgres
Scrollable ResultSet (multipage) - Oracle 7 JDBC 2.0 driver
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:17:52.