🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: aus.computers.java
1 messages
1 total messages Started by Vegard K�sa Wed, 27 Jan 1999 00:00
simple database application in java
#1253
Author: Vegard K�sa
Date: Wed, 27 Jan 1999 00:00
89 lines
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){

   }

  }
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads