Results 1 to 2 of 2
- 12-10-2008, 07:41 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 1
- Rep Power
- 0
Problem conecting to SQL Server 2008
Hi, I'm trying to conect to a database in SQL Server 2008 but I'm having some problems. Here is my code and the error I got.
import java.sql.*;
public class Main {
public static void main(String args[]) {
System.out.println("Testing access to SQLServer\n\n");
Connection conn = null;
String teste = "SELECT Name, Adress FROM TB_Cliente;";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc: odbc: DSK_RENATO", "sa", "mope2008");
System.out.println("successl\n");
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery(test);
while (rs.next()) {
String Nome = rs.getString("Name");
String Endereco = rs.getString("Adress");
System.out.println("Name: " +Name+ " Adress: " + Adress);
System.out.println("---------------------------------------");
}
System.out.println("\n\nSucess!!!\n");
} catch(ClassNotFoundException e) {
System.out.println("excessão Class not found");
e.printStackTrace();
} catch(SQLException e) {
System.out.println("SQL Exception... Error in querry:");
e.printStackTrace();
} finally {
try {
conn.close();
System.out.println("\n\nClosing the conection");
} catch(SQLException erro) {
System.out.println("Error in closing");
erro.printStackTrace();
}
}
}
}
Testing access to SQLServer
SQL Exception... Erro na consulta:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source names not found and none standart driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknow n Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Main.main(Main.java:11)
Exception in thread "main" java.lang.NullPointerException
at Main.main(Main.java:30)
Thanks
- 02-20-2009, 11:16 AM #2
Member
- Join Date
- Jan 2009
- Posts
- 5
- Rep Power
- 0
problem connecting to sql server 2008
according to your error "java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source names not found and none standart driver specified"
it means that you have not yet created a datasource for your database connection. if you are using XP, u can create a datasource by going to
control panel -> administrative tools -> datasources . create a new datasource under the user dsn named dsk_renato, using sql server as your datasource, fill in the other requirements according to ur sql server details and rerun ur java code
Similar Threads
-
Problem connect to SQL Server
By Crisanto in forum EclipseReplies: 1Last Post: 12-02-2008, 12:13 AM -
Problem in Starting JBOSS Server
By 82rathi.angara in forum NetworkingReplies: 0Last Post: 06-16-2008, 02:58 PM -
Having problem in connecting with SQL Server 2005
By rmaadil in forum JDBCReplies: 4Last Post: 05-21-2008, 06:55 AM -
Sql server connection problem
By tanvirtonu in forum JDBCReplies: 1Last Post: 03-31-2008, 12:46 PM -
client-server communication problem
By revathi17 in forum New To JavaReplies: 1Last Post: 08-09-2007, 02:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks