Books Related to Java Technology

Sunday, January 4, 2009

JDBC Prepared Statement Example


import java.io.*;
import java.sql.*;
public class JDBCPreparedStatement {
public static void main ( String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
PreparedStatement stmt = c.prepareStatement("select * from tableName");
ResultSet rs = stmt.executeQuery();
while(rs.next()){
System.out.println(rs.getInt(1) + " (" + rs.getString(2) + ")");
}
} catch(SQLException e){
System.err.println(e);
}
}
}

1 comment: