首页 > 数据库技术 > 详细

JDBC connection

时间:2017-01-19 00:40:11      阅读:301      评论:0      收藏:0      [点我收藏+]

package javaexercise;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

 

public class Q29jdbc {

 static Connection newConnection = null;

 public static Connection getDBConnection() throws SQLException {

  try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/fidelity", "root", "root")) {
   newConnection = con;

  }
  return newConnection;
 }

 public static void main(String[] args) throws SQLException {

  getDBConnection();

  Statement st = newConnection.createStatement();
  
  String sql = "SELECT * FROM t_user";
  ResultSet rs = st.executeQuery(sql);
  //st.executeUpdate("INSERT INTO t_user VALUES(14,‘mabel‘,‘123456‘) ");
 }

}

JDBC connection

原文:http://www.cnblogs.com/mabel/p/6298388.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!