Article View: aus.computers.java
Article #1253simple database application in java
From: Vegard K�sa
Date: Wed, 27 Jan 1999 00:00
Date: Wed, 27 Jan 1999 00:00
89 lines
2714 bytes
2714 bytes
Hello.
I'm trying to make a simple application that reads out a single SELECT *
statement from a MSAccess databasefile.
I get a complaint from the compiler, though, that my connection - object
"conn1" isn't found. What am I doing wrong? I have a feeling that there's
something wrong with the URL that I'm refering to on my local drive.
I also get an error about my DataBaseMetaData statement - this isn't the
most important thing thought, I just thougth it would be neat to get that
information out as well.
Further, I'm trying to use the JDBC - ODBC -bridge, am I doing that right?
Are there any other or more prefferable ways to connect ?
Thanks for all help. My email adress is: vkaasa@c2i.net
Vegard
Here's the code.
import java.sql.*;
public class SqlSelect {
public static void main (String [ ] args){
Statement statement1;
ResultSet rsl;
DataBaseMetaData dbmd1;
try{
try {
Class.forName("jdbc.odbc.music");
}
catch(Exception e){
System.out.println("\n Class not Found Exception");
}
Connection conn1 = DriverManager.getConnection("jdbc:odbc:musikk",
"","");
statement1 = conn1.createStatement();
rsl = statement1.executeQuery("select * from Musikkategorier");
while(rsl.next()){
System.out.println(rsl.getInt("Musikkategori-ID)" + ","));
System.out.println(rsl.getString("Musikkategori"));
}
dbmd1 = conn1.getMetaData();
System.out.println("You are connected to:" +
dbmd1.getDatabaseProductName());
System.out.println("The database version number is:" +
dbmd1.getProductVersion());
ResultSetMetaData rsmd1 = rsl .getMetaData();
for( int i = 1; i <= rsmd1.getColumnCount(); i++ ){
System.out.println("Column " + i + "name is: "
+rsmd1.getColumnName(i));
System.out.println("Column " + i + "size is: "
+rsmd1.getColumnSize(i));
System.out.println("Column " + i + "SQL type is: "
+rsmd1.getColumnType(i));
}
}
catch (SQLException ex){
System.out.println("\n SQL Exception " + ex.getMessage() + "\n");
}
try{
statement1.close();
conn1.close();
}
catch(SQLException e){
}
}
}
Technical Details
Message-ID:
<78nr7q$ks1$1@romeo.dax.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,d83acea1be446088,start X-Google-Attributes: gid10d6db,public From: "Vegard K�sa" <vkaasa@c2i.net> Subject: simple database application in java Date: 1999/01/27 Message-ID: <78nr7q$ks1$1@romeo.dax.net> X-Deja-AN: 437642269 Organization: Tele2 Norway Public Access X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Newsgroups: aus.computers.java