?? service.java
字號:
package helloWorld;
import java.sql.*;
public class Service {
public Service()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public Connection getConnection()
{
Connection conn=null;
try
{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=sa");
return conn;
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
public String sayHello(String aaa) {
Connection conn=getConnection();
PreparedStatement pstat=null;
ResultSet rset=null;
int cnt=0;
try
{
String sql="SELECT * from popo where name=?";
pstat=conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pstat.setString(1, aaa);
rset=pstat.executeQuery();
rset.last();
cnt=rset.getRow();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(rset!=null)rset.close();
if(pstat!=null)pstat.close();
if(conn!=null)conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
if(cnt==1)
return "您的用戶名已被注冊";
return "您的用戶名可以注冊";
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -