- 论坛徽章:
- 0
|
刚学java,网上找了些代码,没有效果,请知道的朋友告诉我一下:),谢谢啦- import java.sql.Connection;
- import java.sql.*;
- public class test0420_2{
-
-
- static Connection conn=null;
- static{
- System.out.println("in DBManager");
- String dbName="test";
- try{
- Class.forName("com.mysql.jdbc.Driver");
- //配置数据源
- String url="jdbc:mysql://192.168.1.189/"+ dbName +
- "?useUnicode=true&characterEncoding=GB2312";
- conn=DriverManager.getConnection(url,"root","");
- }catch(Exception e){
- System.out.println("Exception:"+e.getMessage());
- }
- }
-
- public synchronized static Connection getConnection(){
- Connection temp=null;
- if(conn!=null){
- temp=conn;
- conn=null;
- return temp;
- }else{
- return null;
- }
-
- }
-
- public synchronized static void releaseConnection(Connection con){
- conn=con;
- }
-
- public static void closeConn(){
- try{
- conn.close();
- }catch(SQLException e){
- System.out.println(e.getMessage());
- }
- }
-
- public static void main(String[] args) {
- // TODO Auto-generated method stubimport java.sql.*;
- getConnection();
- }
- }
-
复制代码 我有个机器,用户名是root,密码是无,然后有一个库叫test,一个表格名叫news,有二个字段,一个是title,另一个是content,
然后我,想把“title123”插入title字段,"content456"插入contet字段,请问我上面的代码怎么改才能用 |
|