Creating view in java for mysql is simple.Lets see an example.
import java.sql.*;
public class ViewExample {
public static void createView() {
Connection con = null;
Statement stat = null;
Statement stat1 = null;
Statement stat2 = null;
ResultSet rs = null;
long now = 0;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "username", "password");
stat = con.createStatement();
int b;
stat.executeUpdate("drop view IF EXISTS test.view1");
stat.executeUpdate("CREATE VIEW test.view1(first_name,last_name) AS SELECT s_26_field_13,s_26_field_12 FROM S_26");
stat1 = con.createStatement();
System.out.println("view created ");
stat2 = con.createStatement();
rs = stat.executeQuery("select * from view1");
while (rs.next()) {
System.out.println("first_name -- " + rs.getString("first_name"));
System.out.println("last_name -- " + rs.getString("last_name"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String a[]) {
createView();
}
}
8/17/10
Subscribe to:
Post Comments (Atom)
Popular Posts
-
Hi folks, I got a chance to work with JSF, it was an interesting requirement. Its about a custom component which would be of more use to ...
-
Hi Folks, I would like to share my another POC task in JSF with you all. "Primefaces Dropdown with Pagination & Filter "...
-
We shall create temp table in mysql using the sql script CREATE TEMPORARY TABLE testraghu(name VARCHAR(50) , phone VARCHAR(50)) Let us se...
-
Hi all, i would like to share a simple example of storing haspmap in mysql db. In order to store object into your db, the field type must ...
No comments:
Post a Comment