Extract tables from SQL DB with java
Hi
I have a database called enig212 with a table called TestTable with the fields TestFelt1 and TestFelt2. I hava the folliwng Java code, which should extract the data stored in the to fields, but it doesn't return anything....can anyone see whats wrong?
Code:
/* CIA.java
From http://sqlzoo.net By Andrew Cumming
*/
import java.sql.*;
public class CIA{
public static void main(String[] args){
Connection myCon;
Statement myStmt;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
// Connect to an instance of mysql with the follow details:
// machine address: pc236nt.napier.ac.uk
// database : gisq
// user name : scott
// password : tiger
myCon = DriverManager.getConnection(
"jdbc:mysql://fyr.cs.aau.dk/enig212",
"someusername","somepassword");
myStmt = myCon.createStatement();
ResultSet result = myStmt.executeQuery(
"SELECT TestFelt1 FROM TestTabel");
while (result.next()){
System.out.println(result.getString("*"));
}
myCon.close();
}
catch (Exception sqlEx){
System.err.println(sqlEx);
}
}
}