Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem conmnecting to mssql

Status
Not open for further replies.

ZagorTenay

Programmer
Jul 1, 2005
6
TR
I am trying to connect to mssql database. The error I receive is,

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Baglanti.main(Baglanti.java:12)


Here is the code.. (This is my first code so I have no idea what is happenning)


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**import net.sourceforge.jtds.jdbc.Driver;*/
public class Baglanti {
public static void main(String[] args) throws Exception
{
// TODO Auto-generated method stub
try{
/**Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");*/
Class.forName("net.sourceforge.jtds.jdbc.Driver");

Connection conn;
conn=DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.0.2:1433;DatabaseName=cari2;User=usr1;Passwd=");
/**conn=DriverManager.getConnection("jdbc:eek:dbc:cari2","usr1","");*/
System.out.println(conn.getClass());
Statement query=conn.createStatement();
ResultSet veriler=query.executeQuery("SELECT * FROM Bankalar");
System.out.println("Baglanti kapali: " + conn.isClosed());
System.out.println ("Banka listesi:");

while (veriler.next());
{System.out.println (veriler.getString("Banka"));}
veriler.close();
conn.close();
}

catch (Exception e)
{System.out.println("Hata!!!");}

}
}
 
Which JDK are you compiling it with ? Are you running the same JRE version as the JDK ? Have you got the jtds jar in your CLASSPATH ?

--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks for the reply..
I am using eclipse to write and compile.. I strugled a lot to put the jtds.jar in my classpath.. It gave classnotfound/implemented??.. Something like that.. Then downloaded and put the source file in the class path.. The code did not give any errors about the class but gave this last java.lang error.. I think the problem is with the jtds.jar. How would I check that?

I have jre and jdk version 1.5.0_0.4..

 
When I use try-catch it compiles and gives a classnotfoundException (System.out.print(theexception))..
This is very frustrating.. I downloaded a document on how to use a library in eclipse.. Everything seems normal.. There must be something I am missing..

I put the jar file in my class path. I add the jar from the project-properties menu. That should be all..

Thanks..
 
Is there a red circle with a white cross anywhere in the Baglanti class?

Cheers,

Dian
 
This is exceedingly absurd.. I have been trying this 20 line stupid code for a while.. Suddenly it started to work.. I have done absolutely nothing special..

It now gives another error.. The connection is there.. Do you know by any chance how to fix this?

java.sql.SQLException: Could not find a Java charset equivalent to DB charset iso_1.


Thanks a lot...
Cheers,
Burhan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top