<pre class="java" name="code">public class 连接
{
public static void main(String[] args) throws ClassNotFoundException, SQLException
{
Class.forName("com.mysql.jdbc.Driver");
String st ="jdbc:mysql://localhost:3306/scott";
Connection ct = DriverManager.getConnection(st, "root", "l123456");
Statement sm=ct.createStatement();
String stSql = "select * from emp";
ResultSet rs =sm.executeQuery(stSql);
while(rs.next())
{
Integer nEmpno = rs.getInt("empno");
String stName =rs.getString("ename");
String stJob = rs.getString("job");
System.out.println(nEmpno.toString()+" "+stName+" "+stJob);
}
rs.close();
sm.close();
ct.close();
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class 插入
{
public static void InsertDept(int deptno, String DeptName, String Loc) throws ClassNotFoundException, SQLException
{
Class.forName("oracle.jdbc.driver.OracleDriver");
String st = "jdbc:oracle:thin:@localhost:1521:orcl";
Connection ct = DriverManager.getConnection(st, "scott", "l123456");
Statement sm = ct.createStatement();
String stSQL = "insert into dept values("+deptno+",'"+DeptName+"','"+Loc+ "')";
sm.executeUpdate(stSQL);
sm.close();
ct.close();
}
public static void main(String[] args) throws SQLException, ClassNotFoundException
{
InsertDept(60,"ZhuanYan","JinZhou");
}
}
package com.company;
import java.util.Scanner;
/**
* Created by ttc on 16-10-27.
*/
public class 练习
{
public static void main(String[] args)
{
System.out.println("please input a string:");
Scanner sc = new Scanner(System.in);
String str=sc.nextLine();
int [] word =new int[26];
// for(int j = 0;j<26;j++)
// {
// System.out.print(word[j]);
// }
// System.out.println("");
for(int i=0;i<str.length();i++)
{
char c = str.charAt(i);
if(Character.isLetter(c))
{
int num = word[c - 'a'];
num++;
word[c - 'a'] = num;
}
}
for(int j = 0;j<26;j++)
{
if(word[j]>0)
System.out.println((char)('a'+j)+"出现了"+word[j]+"次");
}
}
}
<pre class="java" name="code">public class 连接
{
public static void main(String[] args) throws ClassNotFoundException, SQLException
{
Class.forName("com.mysql.jdbc.Driver");
String st ="jdbc:mysql://localhost:3306/scott";
Connection ct = DriverManager.getConnection(st, "root", "l123456");
Statement sm=ct.createStatement();
String stSql = "select * from emp";
ResultSet rs =sm.executeQuery(stSql);
while(rs.next())
{
Integer nEmpno = rs.getInt("empno");
String stName =rs.getString("ename");
String stJob = rs.getString("job");
System.out.println(nEmpno.toString()+" "+stName+" "+stJob);
}
rs.close();
sm.close();
ct.close();
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class 插入
{
public static void InsertDept(int deptno, String DeptName, String Loc) throws ClassNotFoundException, SQLException
{
Class.forName("oracle.jdbc.driver.OracleDriver");
String st = "jdbc:oracle:thin:@localhost:1521:orcl";
Connection ct = DriverManager.getConnection(st, "scott", "l123456");
Statement sm = ct.createStatement();
String stSQL = "insert into dept values("+deptno+",'"+DeptName+"','"+Loc+ "')";
sm.executeUpdate(stSQL);
sm.close();
ct.close();
}
public static void main(String[] args) throws SQLException, ClassNotFoundException
{
InsertDept(60,"ZhuanYan","JinZhou");
}
}
jdbc连接
最新推荐文章于 2023-08-29 12:49:14 发布