File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get started with jdbc

 
Alexandre Bellezi Jos�
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam having a problem with jdbc.
I want to insert and retrieve data from a database in SEQUEL SERVER 7 RDBMS on a database server on network.Iam a client to that server and have SEQUEL SERVER (client) installed on my machine.
what are the drivers i need to install and how can i get the connection.
im using the following code and getting the runtime error.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class SimpleConnection1
{
public static void main(String args[])
{
try{Connection con = null;
String url = "jdbc dbc:<database name on server>";
con = DriverManager.getConnection(url,"sa","");
Statement stmt = con.createStatement();
stmt.executeUpdate("INSERT INTO hindi1"+" VALUES(nitin)");
stmt.close();
con.close();
}
catch (Exception e){System.out.println("problem inserting its very tight");}
System.out.println("Connection successful!");}}

 
Carl Trusiak
Sheriff
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to take a look at the Tutorial provided by Sun on JDBC. In your example, you haven't registered a Driver, and you URL appears to be incomplete. One good place to check is if anyone where you work has a working program that does the connection, if not there should be an example program with your JDBC Driver try and start there.
 
Ajay Kumar
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi abj,
As Carl T. has pointed out first of all U need to register the driver for jdbc-odbc. In this case it will be
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

U need to create a DSN (either a UserDSN or System DSN) with your ODBC in the control panel (let's say it is named test1)
Then your connection statement should look like
String url = "jdbc: odbc:test1";
Be sure that your SQL server is up and running and test your DSN thru the ODBC panel before U get all sorts of error messages on the java console.
Reply here if you have any problems and I can mail U some sample code of connecting to a SQL server later in the day.
Thanks
Ajay Kumar

[This message has been edited by Ajay Kumar (edited June 19, 2000).]
 
Alexandre Bellezi Jos�
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont have an odbc driver for sequel installed on my machine. And i tried to download it from net but i could not find any suitable site to download it from.
The code given above compiles well if i use a registered access database but at runtime it gives error that no suitable driver available,sequel state: 08001,error code : 0.
Please give the url from where i can download the jdbc dbc driver for sequel.
thanks in anticipation.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic