Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSP connect to JDBC in Bean

843859Apr 8 2007 — edited Apr 8 2007
This is the program from bean file(MySQL.java)
I have written this program and I want to use JSP to call this bean file.
What's the program? Can anybody show the program to me?
you can provide me if you have some URL which is showing this issue.
Thanks.

package com.jdbc.test;

import java.sql.*;


public class MySQL {

public static void main (String[] args) {

String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/userlogin";
String username = "";
String password = "";
showEmployeeTable(driver, url, username, password);
}

public static void showEmployeeTable(String driver,
String url,
String username,
String password)

{
try{

Class.forName(driver);

Connection connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement();
String query = "Select userid from userlogin";

ResultSet resultSet = statement.executeQuery(query);

while(resultSet.next()){

System.out.print(resultSet.getString("userid"));


}
connection.close();
} catch(ClassNotFoundException cnfe) {
System.err.println("Error loading driver: " + cnfe);
} catch(SQLException sqle) {
System.err.println("Error with connection: " + sqle);
}

}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 6 2007
Added on Apr 8 2007
1 comment
244 views