try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch(Exception ex){
errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("error.conn.database"));}
try{
String url = "jdbc:mysql://localhost/tifs?user=root&password=´´&useUnicode=true&characterEncoding=8859_1";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE); conn.close();
}
catch(Exception ex){ }
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch(Exception ex){
errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("error.conn.database"));}
try{
String url = "jdbc:mysql://localhost/tifs?user=root&password=´´&useUnicode=true&characterEncoding=8859_1";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE); conn.close();
}
catch(Exception ex){ }
解决方案 »
- 怎么将jsp里的java对象传到js里
- 请各位大虾帮俺出出招儿:关于控制页签显示与关闭的控制问题!!!!!!若能解决将高分奉上……!
- java mail 带附件的邮件提示javax.mail.AuthenticationFailedException,发布普通邮件没问题
- WEB项目的实用性!以及客户的可读性!
- 我的jsp服务器报这个错误,请问题怎么处理,谢谢各位大侠,帮帮小弟这个新手,
- 请教dwr+webwork的配置?
- 有个问题,请大家多帮忙(详情请进入)
- mvc在实际工作中的使用
- 急问:tomcat下jsp被tanslate成servlet文件后放在哪里?
- HttpServletRequest的setAttribute()方法时候有容量的限制?有的话大概是多少?
- 初学者的几个问题
- 如果 b类 c方法,调用A类 c方法应该如何书写
import java.sql.*;public class jdbcProxy {
Connection conn = null;
........... public boolean getConnection() {
bollean tag = true;
try {
Class.forName(".....");
.....
conn = DriverManager.getConnection(..........); } catch ( Exception e ) {
e.printStackTrace();
tag = false;
}
return tag;
}
..........
}
import java.sql.*;
import java.lang.*;
public class DbLink
{
String Sa,Password;
Connection Conn=null;
String StrURL="jdbc:odbc:";
String ConnDriver="sun.jdbc.odbc.JdbcDriver";
Statement Stmt=null;
ResultSet rs=null;
public void DbLink(String sa,String password, String URL1)
{StrURL+=URL1;
Sa=sa;
Password=password;
try{
Class.forName(ConnDriver);
}
catch(ClassNotFoundException e)
{
System.err.println(e.getMessage());
}
}
public void DbExcute(String StrSQL)
{
try
{
Conn=DriverManager.getConnection(StrURL,Sa,Password);
Stmt=Conn.createStatement();
Stmt.executeUpdate(StrSQL);
}
catch(SQLException e)
{
System.err.println(e.getMessage());
}
}
public String getstr()
{
return "hello";
}
}
import java.sql.*;
public class DBconn
{String DBDriver="org.gjt.mm.mysql.Driver";
String ConnStr="jdbc:mysql://localhost/data";
String MyUser="root";
String MyPassword="";
Connection conn = null;
Statement stmt=null;
ResultSet rs = null;
public DBconn()
{try
{Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException e)
{System.err.println("DBconn (): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{rs = null;
try
{conn = DriverManager.getConnection(ConnStr,MyUser,MyPassword);
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql){
{
try
{conn = DriverManager.getConnection(ConnStr,MyUser,MyPassword);
Statement stmt = conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
{System.err.println("aq.executeQuery:"+ex.getMessage());
}
}
}
public boolean closeConn()
{
try
{
if (rs!=null) rs.close();
if (stmt!=null) stmt.close();
if (conn!=null) conn.close();
return true;
}
catch ( SQLException ex )
{
System.err.println("closeConn: " + ex.getMessage());
return false;
}
}
}
package database;database就是包
你必须放在myapp/WEB-INF/classes/database