Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

jdbc with as400

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to connect to our as400 to do some custom reports. I have coded this java app
import java.sql.*;
import java.io.*;

public class dbConnect
{

public static void main(String[] args) throws IOException
{
Connection con = null;
try {
class.forName("com.ibm.as400.access.AS400JDBCDriver").newInstance();

// Create a connection to the database
con = DriverManager.getConnection("jdbc:as400://10.220.0.1", "sotony", "lavalle");
if(!con.isClosed())
{
System.out.println("Successfully connected to the AS/400...");
}
}

catch (ClassNotFoundException e)
{ // Could not find the database driver
System.out.println("Could not find db driver");
}

catch (SQLException e)
{ // Could not connect to the database
System.out.println("Could not connect to db");
}

catch (Exception e)
{ // General Error
System.out.println("Error");
}
}
}

i keep getting these for errors what am I doing wrong?

C:\Program Files\Java\jdk1.5.0_09\projects\dbConnect\src\dbConnect.java:19: <identifier> expected
class.forName("com.ibm.as400.access.AS400JDBCDriver").newInstance();
^
C:\Program Files\Java\jdk1.5.0_09\projects\dbConnect\src\dbConnect.java:19: '{' expected
class.forName("com.ibm.as400.access.AS400JDBCDriver").newInstance();
^
C:\Program Files\Java\jdk1.5.0_09\projects\dbConnect\src\dbConnect.java:22: <identifier> expected
con = DriverManager.getConnection("jdbc:as400://10.220.0.1", "sotony", "lavalle");
^
C:\Program Files\Java\jdk1.5.0_09\projects\dbConnect\src\dbConnect.java:23: illegal start of type
if(!con.isClosed())
^
C:\Program Files\Java\jdk1.5.0_09\projects\dbConnect\src\dbConnect.java:27: <identifier> expected
}
^
C:\Program Files\Java\jdk1.5.0_09\projects\dbConnect\src\dbConnect.java:29: 'catch' without 'try'
catch (ClassNotFoundException e)
^
C:\Program Files\Java\jdk1.5.0_09\projects\dbConnect\src\dbConnect.java:18: 'try' without 'catch' or 'finally'
try {
^
C:\Program Files\Java\jdk1.5.0_09\projects\dbConnect\src\dbConnect.java:45: '}' expected
 
author & internet detective
Posts: 40200
816
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony,
class.forName should be Class.forName - note the capital C.

I think this is causing some of the later errors. Try fixing it and see what errors (if any) you get then.
 
Tony Lavalle
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I can not believe i missed that.
 
today's feeble attempt to support the empire
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic