I wrote a java class to get values from a Mysql db in an Xpage. The code is,
package com.vijay;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
String name;
String caty;
float price;
private Connection con;
private Statement st;
private ResultSet rs;
public String test(){
return "This is a class with just a single method";
}
public Test(){
}
public void db(){
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/vijay","root","");
st=con.createStatement();
st.executeQuery("select * from prodet;");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.getMethod();
}
public void getMethod(){
try {
while(rs.next()){
name=rs.getString("name");
price=rs.getFloat("price");
caty = rs.getString("caty");
}
con.close();
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I put a label in the page and Computed its value with SSJS
var v = new com.vijay.Test();
v.db();
v.getMethod();
return v.name;
Even i put those two methods in the constructor too. But doesn't work.
Where do i miss?