/ * java class * /
package com.tutoria;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
public class dbhandler {
Connection conn ;
public dbhandler()
{
conn = null;
String userName = "root";
String password = "1234";
String serverName = "localhost";
int portNumber = 3306;
String dbName = "a2";
try {
conn = null;
Properties connectionProps = new Properties();
connectionProps.put("user", userName);
connectionProps.put("password", password);
System.out.println("trying to get connection!! :)");
conn = DriverManager.getConnection("jdbc:mysql://" + serverName
+ ":" + portNumber + "/" + dbName, connectionProps);
System.out.println(" Connection achieved!! ");
//conn.close();
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Exception " +e);
}
}
public boolean create_account (String table)
{
return true;
}
public boolean insertplayer()
{
return true;
}
public String getid()
{
String a=null;
String sqlquery="Select * from student "+" where id='145' "; try{
PreparedStatement Stat1=(PreparedStatement)conn.prepareStatement(sqlquery);
ResultSet Rset=Stat1.executeQuery(sqlquery);
while (Rset.next())
{
a=Rset.getString(2);
}}catch (Exception e){
System.out.println(e);}return a;
}}
/* xhtml*/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:form>
<h:panelGrid columns="2">
<h:outputText value="Name"></h:outputText>
<h:inputText value="#{person.name}"></h:inputText>
<h:outputText value="Password"></h:outputText>
<h:inputText value="#{person.id}"></h:inputText>
<h:commandButton value="Login" action="#{loginBean.idreturn}">
</h:commandButton>
</h:panelGrid>
</h:form>
</html>
/ *我添加了连接器的jar文件,但它仍然没有显示驱动程序 当我只运行java类文件时,它会检索结果而不会给出任何错误..如果有人知道这有帮助我。谢谢你的进步.. * /