Help with Java Database Query
Can someone guide me to a tutorial or some code that will show me how to return a result set and how I can use the resultset to populate an HTML/Javascript form?
Here is what I have done so far with Java (this compiles but I am not sure how to populate myResults):
///THANK YOU IN ADVANCE//////
import java.sql.*;
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
//These are bein imported, because eventually I want to pass them to an applet in HTML.
public class LoadDriver
{
private static String myResults = "";
public static void main(String[] Args)
{//0
try//1
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch (Exception E)//1
{
System.err.println("Unable to load driver.");
E.printStackTrace();
}
}//0
public static String showTableImad()
{
try//2
{
Connection C = DriverManager.getConnection("jdbc:mysql://xxx.xxx.xxx/username?user=myname&password=mypass");
///////////////////////////
///////////////////////////
try//3
{
String tableName = "vars";
Statement Stmt = C.createStatement();
ResultSet RS = Stmt.executeQuery("select albumOwner from counter");
while (RS.next())
{
///THIS IS WHERE I need to collec the info I THINK
}
RS.close();
Stmt.close();
C.close();
}
catch (SQLException E)//3
{
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}
////////////////////////
////////////////////////
}
catch (SQLException E)//2
{
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}
return myResults;
}
}:confused: :confused: :confused: :mad: