Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
process with throw about four exceptions. JDBC drivers are out
try {
Class.forName("org.gjt.mm.mysql.Driver").newIns
tance();//1
Connection c =
DriverManager.getConnection("jdbc:mysql://local
host:3306/test?
user=admin;password=admin","","");//2
e.printStackTrace();
Statement stmt =
connection.createStatement();//1
ResultSet rs = stmt.executeQuery("select
* from mytable");//2
while(rs.next())//3
System.out.println("teststr=" +
rs.getString("teststr"));//4
}
that created it. Line 2 actually executes the query and returns
returns true. Line 4 grabs a string from this row. You call
rs.getType(), where Type is the type of data you want. You can
either pass the String name of the column, or the integer index
of the column.
Now it's time to clean up. Not too hard, as you will see :)
rs.close();
stmt.close();
connection.close();
OK, now you can do SELECT statements all you want :). Now,
made: http://www.pscode.com/vb/scripts/ShowCode.asp?
you to ensure that you replace any ' with \' WHENEVER you